#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.8.1
 Author:         myName

 Script Function:
	Template AutoIt script.

#ce ----------------------------------------------------------------------------




;Func process_work(ByRef $hWnd, ByRef $Msg, ByRef $iIDTimer, ByRef $dwTime)
Func process_work($hWnd, $Msg, $iIDTimer, $dwTime)
   If Not check_work() Then Return False
   ;_DebugOut("process " & $dwTime)
   For $pos = 1 To $flag_work[0]
	  If $flag_work[$pos] Then
		 ;_DebugOut("process " & $dwTime & " pos=" & $pos & " step=" & $step[$pos])
		 Switch $step[$pos]
			   Case -2
			   ; make move to next
			   If make_move($pos) Then
				  message($pos,"wait move")
				  $step[$pos] = -1;
				  $substep[$pos] = 0
				  $tmp_value[$pos] = -1
			   EndIf
			Case -1
			   ; check for end move
			   If done_move($pos) Then
				  message($pos,"move done")
				  $step[$pos] = 0;
				  $substep[$pos] = 0
				  $tmp_value[$pos] = -1
			   EndIf
			Case 0 To UBound($actions) - 1
			   ; check actions
			   If $need_action[$pos][$step[$pos]] Then
				  ;_DebugOut("call: " & $actions[$step[$pos]][1] & "( " & $pos & ")")
				  If Call($actions[$step[$pos]][1],$pos) Then
					; _DebugOut("continue")
					 ContinueLoop
				  EndIf
				 ; _DebugOut("next step")
			   EndIf
			   $step[$pos] += 1
			   $substep[$pos] = 0
			   $tmp_value[$pos] = -1
			   If $step[$pos] >= UBound($actions) Then
				  $step[$pos] = -2
			   EndIf
		 EndSwitch
	  EndIf
   Next
EndFunc

Func message($pos,$str)
   Local $p = $winlist[$pos]
   GUICtrlSetData($p[$index_label],$str)
EndFunc

Func make_move($pos)
   Local $p = $winlist[$pos]
   Local $r = ControlClick($p[$index_handle],"",$control_ff,"left",1,$move[0],$move[1])
   If $r = 0 Then _DebugOut("error")
   Return True
EndFunc

Func done_move($pos)
   Local $p = $winlist[$pos]
   $substep[$pos] += 1
   Local $color = PixelGetColor($p[0] + $p[2] + $move[2],$p[1] + $p[3] + $move[3],$p[$index_handle])
   ;_DebugOut("s=" & $substep[$pos] & " " & Hex($color,6) & " cmp " & Hex($move[4],6))
   If $color = $move[4] Then
	  Return True
   Else
	  Return False
   EndIf
EndFunc

